package com.林子祺.CAT旅游系统.dao.deal;

import com.林子祺.CAT旅游系统.entity.login.LoginStatus;

import java.sql.*;

public class DeleteBuy {

    public static void delete(int ticket_id,String name,double refund){
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelsys", "root", "@Blink102417");

            double left = LoginStatus.money+refund;

            String sql = "delete from ticketbuy where order_id = "+ticket_id;

            String sql1 = "update user set money = "+left+" where name = "+"'"+name+"'";

            stmt = conn.createStatement();

            stmt.execute(sql);
            stmt.execute(sql1);

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            if(rs != null) {
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(conn != null) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }

}
